<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-button plain  @click="abc(0)">初筛{{statisticsNum.count0}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain  @click="abc(1)" >面试{{statisticsNum.count1}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain  @click="abc(2)" >录用{{statisticsNum.count2}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button type="primary" @click="abc(3)" >已录用{{statisticsNum.count3}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain  @click="abc(4)" >淘汰{{statisticsNum.count4}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-form-item  prop="resumeName">
        <el-input
          v-model="queryParams.query"
          placeholder="请输入简历名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-s-promotion"
          size="mini"
          :disabled="multiple"
          @click="handleUpdate()"
          v-hasPermi="['system:auitvo:edit']"
        >推送
        </el-button>

      </el-col>


&lt;!&ndash;      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeletes()"
          v-hasPermi="['system:auitvo:updateIsFirst']"
        >面试不通过</el-button>
      </el-col>&ndash;&gt;

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:auitvo:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="auitvoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="候选人名称" align="center" prop="resumeName"  />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="应聘职位" align="center" prop="stationName" />
      <el-table-column label="企业名称" align="center" prop="companyName" />
      <el-table-column label="负责商务" align="center" prop="createName" />
      <el-table-column label="状态" align="center" prop="isFirst">
        <template  slot-scope="scope">
          <span v-if="scope.row.isFirst == 0">
           待初筛
          </span>
          <span v-if="scope.row.isFirst == 1">
           待面试
          </span>
          <span v-if="scope.row.isFirst == 2">
                           待录用
          </span>
          <span v-if="scope.row.isFirst == 3">
           待入职
          </span>
          <span v-if="scope.row.isFirst == 6">
           已入职
          </span>
        </template>




      </el-table-column>
      <el-table-column label="录用时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>


<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row.id)"
            v-hasPermi="['system:auitvo:edit']"
          >通过录用</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="dialog(scope.row.id,scope.row.resumeId,scope.row.isFirst)"
          >淘汰</el-button>
&lt;!&ndash;          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDeletes(scope.row.id,scope.row.resumeId)"
            v-hasPermi="['system:auitvo:updateIsFirst']"
          >面试不通过</el-button>&ndash;&gt;
&lt;!&ndash;          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="downloadFile(scope.row.imgPath)"
            v-hasPermi="['system:files:download']"
          >简历下载</el-button>&ndash;&gt;
          &lt;!&ndash;
淘汰弹出框
&ndash;&gt;

          <el-dialog
            title="提示"
            :visible.sync="dialogVisible"
            width="30%"
            :before-close="handleClose">
            <span>请输入淘汰原因</span>
            <br>
            <br>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入淘汰原因"
              v-model="soeliminate">
            </el-input>
            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleDeletes()">确 定</el-button>
  </span>
          </el-dialog>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {updateIsFirst, listAuitvo, addAuitvo, updateAuitvo, statisticsNum} from "@/api/system/auitvo";

export default {
  name: "Auitvo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      id:null,
      resumeId:null,
      isFirst:null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      /*淘汰原因*/
      soeliminate:null,
      /*淘汰阶段*/
      ofeliminate:null,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      auitvoList: [],
      statisticsNum:{
        count0:null,
        count1:null,
        count2:null,
        count3:null,
        count4:null
      },
      dialogVisible: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isFirst: 3,
        stationSecond: null,
        resumeName: null,
        phone: null,
        companyName: null,
        stationName: null,
        companyPhone: null,
        companyMailbox: null,
        query:null,
        beginTime:null,
        endTime:null,
        imgPath:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      resumeIds:[]

    };
  },
  created() {
    this.getList();
    this.statistics();
  },
  methods: {
    abc(s) {
      var path = null;
      if (s == 0){
        path = 'screened'
      }
      if (s == 1){
        path = 'auitvo'
      }
      if (s == 2){
        path = 'company'
      }
      if (s == 3){
        path = 'employed'
      }
      if (s == 4){
        path = 'obsolete'
      }

      this.$router.push({ path: '/resume/auitvo/'+ path,query:{}}  ).catch(()=>{})
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listAuitvo(this.queryParams).then(response => {

        this.auitvoList = response.rows;
        this.total = response.total;
      });
      this.loading = false;
    },
    /** 统计数量 */
    statistics() {
      statisticsNum().then(response => {
        this.statisticsNum = response.data;

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        isFirst: 3,
        stationSecond: null,
        createTime: null,
        resumeName: null,
        phone: null,
        companyName: null,
        stationName: null,
        companyPhone: null,
        companyMailbox: null,
        imgPath:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams ={
        pageNum: 1,
        pageSize: 10,
        isFirst: 3,
        stationSecond: null,
        resumeName: null,
        phone: null,
        companyName: null,
        stationName: null,
        companyPhone: null,
        companyMailbox: null,
        query:null,
        beginTime:null,
        endTime:null,
        imgPath:null
      }
      this.resetForm("queryForm");
      this.handleQuery();
      this.statistics();
    },
    dialog(id,resumeId,isFirst){
      this.id =id;
      this.resumeId = resumeId;
      this.isFirst =isFirst;
      this.dialogVisible=true;

    },
    // 多选框选中数据
    handleSelectionChange(selection) {

      this.resumeIds = selection.map(a =>a.resumeId)
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 面试批量通过按钮操作 */
    handleUpdate(id) {
      const ids = id || this.ids
      var is_first = 3;
      this.$modal.confirm('是否确认推送').then(function() {
        return updateAuitvo(ids,is_first);
      }).then(() => {
        this.$modal.msgSuccess("推送成功");
      }).catch(() => {});
    },
    /** 面试批量淘汰 */
    handleDeletes() {
      const ids = this.id || this.ids
      const resumeIds = this.resumeId|| this.resumeIds
      var ofeliminate =this.isFirst
      var soeliminate = this.soeliminate
      if (soeliminate == null || soeliminate == '' ){
        alert("请输入淘汰原因")
        return;
      }

      this.$modal.confirm('是否确认淘汰').then(function() {
        return updateIsFirst(ids,resumeIds,ofeliminate,soeliminate);
      }).then(() => {
        this.soeliminate=null;
        this.dialogVisible=false;
        this.getList();
        this.statistics();
        this.$modal.msgSuccess("淘汰成功");
      }).catch(() => {});
    },
    /** 下载按钮 */
    downloadFile(imgPath) {
      this.$download.previewPdf(imgPath)
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAuitvo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAuitvo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/auitvo/export', {
        ...this.queryParams
      }, `auitvo_${new Date().getTime()}.xlsx`)
    },



  }
};
</script>
